import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

import com.android.networking.message.ControlMessage;
import com.android.networking.message.ControlRquestType;
import com.android.networking.message.DataMessage;


public class Client implements ControlRquestType{
	static ObjectOutputStream out;
	static ObjectInputStream in;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			System.out.println("Connecting to server");
	    	Socket socket = new Socket("192.168.0.196",5559);
	    	System.out.println("*************************");
	    	//out = new ObjectOutputStream(socket.getOutputStream());
			//out.flush();
			//in = new ObjectInputStream(socket.getInputStream());
			BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			System.out.println(input);
			int i=0;
			while(i<5){
				Object obj = input.readLine();
				DataMessage m = DataMessage.getControlMessageInstance(obj.toString());
				i++;
			}
			socket.close();
			//3: Communicating with the server
			//String message=null;
			//int i =0;
			//do{
				/*try{
					Object message = in.readObject();
					System.out.println("message"+message.getClass());
					if(message instanceof DataMessage){
						System.out.println("Recieved the object of Control Message");
					}
					//ControlMessage msg = new ControlMessage("192.168.0.195",
							//5555,1,"192.168.0.1",0,0,"");
					//msg.createNewConnection();
					//sendMessage(message);
				}
				catch(Exception classNot){
					System.err.println("data received in unknown format");
					classNot.printStackTrace();
					//break;
				}*/
				//i++;
			//}while(i<10);
			//out.close();
			
	    	}catch(Exception ex){
	    		ex.printStackTrace();
	    	}
	}
	
	static void sendMessage(Object msg)
	{
		try{			
			out.writeObject(msg);
			out.flush();
			//System.out.println("client>" + msg);
		}
		catch(IOException ioException){
			ioException.printStackTrace();
		}
	}
}
